# -*- coding:utf-8 -*-
# @Time: 2020/7/13 17:09
# @Author: liupengfei
# @File: serializers.py
from rest_framework import serializers

from .models import Comment


class CommentSerializers(serializers.ModelSerializer):
    childs = serializers.SerializerMethodField()

    def get_childs(self, obj):
        comments = Comment.objects.filter(parent=obj)
        return CommentSerializers(instance=comments, many=True).data

    class Meta:
        model = Comment
        fields = '__all__'

